const util = {
	getCookie(name){
	    if (document.cookie.length>0){
	      var c_start=document.cookie.indexOf(name + "=")
	      if (c_start!=-1){
	        c_start=c_start + name.length+1
	        var c_end=document.cookie.indexOf(";",c_start)
	        if (c_end==-1) c_end=document.cookie.length
	            return unescape(document.cookie.substring(c_start,c_end))
	        }
	    }
	    return ""
	},
	addCookie(name,value,expireHours){
	    var cookieString=name+"="+value+"; path=/";
	    //判断是否设置过期时间
	    if(expireHours>0){
	        var date=new Date();
	        date.setTime(date.getTime+expireHours*3600*1000);
	        cookieString=cookieString+"; expire="+date.toGMTString();
	    }
	    document.cookie=cookieString;
	},
	delCookie(name){
	    var exp = new Date();
	    exp.setTime(exp.getTime() - 1);
	    var cval=util.getCookie(name);
	    if(cval!=null) document.cookie= name + "="+cval+"; path=/;expires="+exp.toGMTString();
	},
	//支付方式
    setPayType(status) {
        var res = '';
        switch (status) {
            case 1:
                res = '现金支付';
                break;
            case 2:
                res = '银行卡转账';
                break;
        }
        return res;
    },
    //分拣中心收货订单状态
    setPackageOrderStatus(status){
        var res ='';
        switch (status) {
            case 1:
                res='已提交';
                break;
            case 2:
                res='已付款';
                break;
            case 6:
                res='已取消';
                break;
        }
        return res; 
    },
    //分拣中心销售订单状态
    setOrderStatusSeller(status){
        var res ='';
        switch (status) {
            case 0:
                res='称重中';
                break;
            case 3:
                res='已发运';
                break;
            case 4:
                res='已收运';
                break;
        }
        return res;
    },
    //服务亭收货订单状态
    setOrderStatus(status){
        var res ='';
        switch (status) {
            case 2:
                res='已支付';
                break;
            case 3:
                res='已交货';
                break;
            case 5:
                res='已销售';
                break;    
            case 6:
                res='已取消';
                break;
        }
        return res; 
    },
    //服务亭交货状态
	setOrderStatus2(status){
        var res ='';
        switch (status) {
            case 1:
                res='提交成功';
                break;
            case 2:
                res='接单成功';
                break;
            case 3:
                res='取货成功';
                break;  
            case 4:
                res='验货成功';
                break;
            case 5:
                res='结算成功';
               break;
        }
        return res; 

    },
	//返回 ：2017-11-02 11:11
	getDateTime(timestamp){
	    var now = new Date();
	    now.setTime(timestamp);
	    var year = now.getFullYear();
	    var month=now.getMonth()+1;
	    var date=now.getDate();
	    var hour=now.getHours();
	    var minute=now.getMinutes();
	    var second = now.getSeconds();

	    //return year + "-" + util.toDou(month)+"-"+util.toDou(date)+" "+" "+util.toDou(hour)+":"+util.toDou(minute)+":"+util.toDou(second);
        return year + "-" + util.toDou(month) + "-" + util.toDou(date);
	},
    //格式化日期 2018-08-01
    formatDate(date){
        var year = date.getFullYear();
        var month=date.getMonth()+1;
        var date=date.getDate();

        return year + "-" + util.toDou(month) + "-" + util.toDou(date);
    },
	//补零
	toDou(n){
	    return n >= 10 ? '' + n : '0' + n
	},
	//检测是不是微信内置浏览器
	isWeiXin(){
		var ua = window.navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i) == 'micromessenger'){
			return true;
		}else{
			return false;
		}
	}
}

export default util
